package com.example.design;

import java.util.ArrayList;
import java.util.List;

public class OOPTest {
    public static void main(String[] args) {
        //继承
        Dog dog = new Dog("旺财",4);
        System.out.println(dog.shout());

        //多态
        Cat animal = new Cat();
        Cat cat1 = new Cat();

        animal.shout();
        System.out.println(animal.shout());

        //泛型

    }
}


class Animal{
    protected String name;
    protected int shoutNum;
    public Animal() {
    }
    public Animal(String name, int shoutNum) {
        this.name = name;
        this.shoutNum = shoutNum;
    }

    public String shout(){

        return "是啥";
    }


}

//继承
class Dog extends Animal implements Eat,Swim {

    public Dog(String name, int shoutNum) {
        super(name, shoutNum);
    }

    @Override
    public String shout(){
        String result = "";
        for (int i = 0; i < shoutNum; i++) {
            result = result + "汪，";
        }
        return String.format("%s:叫“%s”", name, result);
    }

    @Override
    public void eat() {
        System.out.println("吃骨头");
    }

    @Override
    public void swim() {
        System.out.println("狗刨");
    }
}

//多态
class Cat extends Animal implements Eat{

    @Override
    public String shout(){
        return "喵";
    }

    //该方法是子类特有的，多态时无法调用
    public void catchMouse(){
        System.out.println("捉到了小杰瑞");
    }

    @Override
    public void eat() {
        System.out.println("吃鱼");
    }
}

class Frog extends Animal implements Swim{
    @Override
    public String shout(){
        return "呱";
    }

    @Override
    public void swim() {
        System.out.println("蛙泳");
    }
}




